<?php
/**
 * Piwik - Open source web analytics
 * 
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 * @version $Id: Controller.php 268 2013-03-22 06:33:38Z jobarthel@gmail.com $
 *
 * @category Piwik_Plugins
 * @package Piwik_OXID_Plugin
 */
class Piwik_OxidPlugin_Controller extends Piwik_Controller
{

	/**
	 * See the result on piwik/?module=OxidPlugin&action=revenueWidget 
	 * or in the dashboard > Add a new widget. 
	 * This widget shows the yearly, monthly and daily revenue of an OXID eShop
	 */
	function revenueWidget()
	{
		include PIWIK_INCLUDE_PATH . '/plugins/OxidPlugin/conf/'.'config.inc.php';
                if ($this->DebugMode) logfile('debug', 'revenueWidget');
		
                $this->SiteID = Piwik_Common::getRequestVar('idSite');
		$siteCurrency = Piwik::getCurrency(Piwik_Common::getRequestVar('idSite'));
		$db = openDB($this);
                
                $sRevenueSelect = 'SELECT COUNT(*) AS totalnum, SUM(oxtotalordersum) AS totalsum '
			 . 'FROM oxorder '
			 . 'WHERE oxstorno = 0 '
                         . 'AND oxshopid = ' . $this->ShopID[$this->SiteID] . ' '
			 . 'AND ';
                $sMarginSelect = 'SELECT  '
                        . 'SUM('
                            . 'ROUND(d.oxnetprice,2) - '
                            . 'ROUND('
                                . 'IF(a.oxparentid=\'\', a.oxbprice, IF(a.oxbprice=0.0, (SELECT b.oxbprice FROM oxarticles b where b.oxid = a.oxparentid), a.oxbprice) )*d.oxamount'
                                .', 2'
                                . ') '
                            . ') '
                        . 'AS netmargin '
                        . 'FROM oxorderarticles d, oxorder o, oxarticles a '
                        . 'WHERE d.oxorderid = o.oxid AND d.oxartid = a.oxid '
                            . 'AND o.oxstorno = 0 AND d.oxstorno = 0 '
                            . 'AND o.oxshopid = ' . $this->ShopID[$this->SiteID] . ' '
                            . 'AND  ';

                // Select Revenue of previous Year
                $sTimeCond = 'YEAR(oxorderdate) = YEAR(CURDATE())-1 ';
                $sql = $sRevenueSelect . $sTimeCond;
                if ($this->DebugMode) logfile('debug', $sql);
		$result = $db->query($sql);
		$data = $result->fetch(PDO::FETCH_ASSOC);
		$revenuePrevYear = $data['totalsum'];
		$countPrevYear = $data['totalnum'];
                
                $sql = $sMarginSelect . $sTimeCond;
		$result = $db->query($sql);
		$data = $result->fetch(PDO::FETCH_ASSOC);
                $marginPrevYear = $data['netmargin'];

		// Select Revenue of this Year
                $sTimeCond = 'YEAR(oxorderdate) = YEAR(CURDATE()) ';
                $sql = $sRevenueSelect . $sTimeCond;
		$result = $db->query($sql);
		$data = $result->fetch(PDO::FETCH_ASSOC);
		$revenueThisYear = $data['totalsum'];
		$countThisYear = $data['totalnum'];
                
                $sql = $sMarginSelect . $sTimeCond;
		$result = $db->query($sql);
		$data = $result->fetch(PDO::FETCH_ASSOC);
                $marginThisYear = $data['netmargin'];
		
		// Select Revenue of Previous Month
                if (date("n") == 1) {
                    $nPrevMonth = 12;
                    $nYear = date("Y") - 1;
                }
                else {
                    $nPrevMonth = date("n") - 1;
                    $nYear = date("Y");
                }
                $sTimeCond = 'YEAR(oxorderdate) = ' . $nYear . ' '
			 . 'AND MONTH(oxorderdate) = ' . $nPrevMonth . ' ';
                $sql = $sRevenueSelect . $sTimeCond;
		$result = $db->query($sql);
		$data = $result->fetch(PDO::FETCH_ASSOC);
		$revenuePrevMonth = $data['totalsum'];
		$countPrevMonth = $data['totalnum'];
                
                $sql = $sMarginSelect . $sTimeCond;
		$result = $db->query($sql);
		$data = $result->fetch(PDO::FETCH_ASSOC);
                $marginPrevMonth = $data['netmargin'];
		
		// Select Revenue of This Month
                $sTimeCond = 'YEAR(oxorderdate) = YEAR(CURDATE()) '
			 . 'AND MONTH(oxorderdate) = MONTH(CURDATE()) ';
                $sql = $sRevenueSelect . $sTimeCond;
		$result = $db->query($sql);
		$data = $result->fetch(PDO::FETCH_ASSOC);
		$revenueThisMonth = $data['totalsum'];
		$countThisMonth = $data['totalnum'];
                
                $sql = $sMarginSelect . $sTimeCond;
		$result = $db->query($sql);
		$data = $result->fetch(PDO::FETCH_ASSOC);
                $marginThisMonth = $data['netmargin'];
		
		// Select Revenue of previous week
		// week(oxorderdate,3)
                $startDays = '-'. (date("N")+6) . ' days';
                $dWeekStart = date("Y-m-d", strtotime($startDays));
                $endDays = '-'. date("N") . ' days';
                $dWeekEnd = date("Y-m-d", strtotime($endDays));
                $sTimeCond = 'DATE(oxorderdate) >= \'' . $dWeekStart . '\' '
			 . 'AND DATE(oxorderdate) <= \'' . $dWeekEnd . '\' ';
                $sql = $sRevenueSelect . $sTimeCond;
                $result = $db->query($sql);
		$data = $result->fetch(PDO::FETCH_ASSOC);
		$revenuePrevWeek = $data['totalsum'];
		$countPrevWeek = $data['totalnum'];
                
                $sql = $sMarginSelect . $sTimeCond;
		$result = $db->query($sql);
		$data = $result->fetch(PDO::FETCH_ASSOC);
                $marginPrevWeek = $data['netmargin'];
		
		// Select Revenue of this week
		// week(oxorderdate,3)
                $startDays = '-'. (date("N")-1) . ' days';
                $dWeekStart = date("Y-m-d", strtotime($startDays));
                $sTimeCond = 'DATE(oxorderdate) >= \'' . $dWeekStart . '\' '
			 . 'AND DATE(oxorderdate) <= DATE(CURDATE()) ';
                $sql = $sRevenueSelect . $sTimeCond;
		$result = $db->query($sql);
		$data = $result->fetch(PDO::FETCH_ASSOC);
		$revenueThisWeek = $data['totalsum'];
		$countThisWeek = $data['totalnum'];
                
                $sql = $sMarginSelect . $sTimeCond;
		$result = $db->query($sql);
		$data = $result->fetch(PDO::FETCH_ASSOC);
                $marginThisWeek = $data['netmargin'];
		
		// Select Revenue of Yesterday
                $sTimeCond = 'DATE(oxorderdate) = DATE_ADD(CURDATE(), INTERVAL -1 DAY) ';
                $sql = $sRevenueSelect . $sTimeCond;
		$result = $db->query($sql);
		$data = $result->fetch(PDO::FETCH_ASSOC);
		$revenueYesterday = $data['totalsum'];
		$countYesterday = $data['totalnum'];
                
                $sql = $sMarginSelect . $sTimeCond;
		$result = $db->query($sql);
		$data = $result->fetch(PDO::FETCH_ASSOC);
                $marginYesterday = $data['netmargin'];
		
		// Select Revenue of Today
                $sTimeCond = 'DATE(oxorderdate) = CURDATE() ';
                $sql = $sRevenueSelect . $sTimeCond;
		$result = $db->query($sql);
		$data = $result->fetch(PDO::FETCH_ASSOC);
		$revenueToday = $data['totalsum'];
		$countToday = $data['totalnum'];
                
                $sql = $sMarginSelect . $sTimeCond;
		$result = $db->query($sql);
		$data = $result->fetch(PDO::FETCH_ASSOC);
                $marginToday = $data['netmargin'];
		
		$db = null;
		
                $daysPerYear = 337 + date("t", strtotime(date("Y")."-02-01"));
                $view = Piwik_View::factory('eshopRevenue');
                
                /* calcuate forecast revenue */
                $view->revenueForecastYear = $revenueThisYear / (date("z")/$daysPerYear);
                $view->revenueForecastMonth = $revenueThisMonth / (date("j")/date("t"));
                $view->revenueForecastWeek = $revenueThisWeek / (dayofWeek($this)/7.0);
                $view->revenueForecastDay = $revenueToday / ((date("G")+date("i")/60.0)/24.0);
                
                /* calcuate forecast margin */
                $view->marginForecastYear = $marginThisYear / (date("z")/$daysPerYear);
                $view->marginForecastMonth = $marginThisMonth / (date("j")/date("t"));
                $view->marginForecastWeek = $marginThisWeek / (dayofWeek($this)/7.0);
                $view->marginForecastDay = $marginToday / ((date("G")+date("i")/60.0)/24.0);

                /* calculate revenue trends */
                if ($revenuePrevYear != 0.0)
                    $view->revenueTrendYear = $view->revenueForecastYear/$revenuePrevYear*100.0 - 100.0;
                else
                    $view->revenueTrendYear = 100.0;
                if ($revenuePrevMonth != 0.0)
                    $view->revenueTrendMonth = $view->revenueForecastMonth/$revenuePrevMonth*100.0 - 100.0;
                else
                    $view->revenueTrendMonth = 100.0;
                if ($revenuePrevWeek != 0.0)
                    $view->revenueTrendWeek = $view->revenueForecastWeek/$revenuePrevWeek*100.0 - 100.0;
                else
                    $view->revenueTrendWeek = 100.0;
                if ($revenueYesterday != 0.0)
                    $view->revenueTrendDay = $view->revenueForecastDay/$revenueYesterday*100.0 - 100.0;
                else
                    $view->revenueTrendDay = 100.0;

                /* calculate margin trends */
                if ($marginPrevYear != 0.0)
                    $view->marginTrendYear = $view->marginForecastYear/$marginPrevYear*100.0 - 100.0;
                else
                    $view->marginTrendYear = 100.0;
                if ($marginPrevMonth != 0.0)
                    $view->marginTrendMonth = $view->marginForecastMonth/$marginPrevMonth*100.0 - 100.0;
                else
                    $view->marginTrendMonth = 100.0;
                if ($marginPrevWeek != 0.0)
                    $view->trendWeek = $view->marginForecastWeek/$marginPrevWeek*100.0 - 100.0;
                else
                    $view->marginTrendWeek = 100.0;
                if ($marginYesterday != 0.0)
                    $view->marginTrendDay = $view->marginForecastDay/$marginYesterday*100.0 - 100.0;
                else
                    $view->marginTrendDay = 100.0;

                $view->nl = chr(13);
                $linkText = ' <a href="javascript:broadcast.propagateAjax(\'module=OxidPlugin&action=oxidMenuRevenue\')">'
                            . Piwik_Translate('OxidPlugin_oxidWidgets') . ' - ' . Piwik_Translate('OxidPlugin_Revenue')
                            . '</a>';
                $view->footerMessage = Piwik_Translate('General_GoTo', $linkText);
                
                $view->siteCurrency = $siteCurrency;
		$view->revenuePrevYear =  $revenuePrevYear;
		$view->countPrevYear = $countPrevYear;
                $view->marginPrevYear = $marginPrevYear;
		$view->revenueThisYear =  $revenueThisYear;
		$view->countThisYear = $countThisYear;
                $view->marginThisYear = $marginThisYear;
		$view->revenuePrevMonth =  $revenuePrevMonth;
		$view->countPrevMonth = $countPrevMonth;
                $view->marginPrevMonth = $marginPrevMonth;
		$view->revenueThisMonth =  $revenueThisMonth;
		$view->countThisMonth = $countThisMonth;
                $view->marginThisMonth = $marginThisMonth;
		$view->revenuePrevWeek  =  $revenuePrevWeek;
		$view->countPrevWeek = $countPrevWeek;
                $view->marginPrevWeek = $marginPrevWeek;
		$view->revenueThisWeek  =  $revenueThisWeek;
		$view->countThisWeek = $countThisWeek;
                $view->marginThisWeek = $marginThisWeek;
		$view->revenueYesterday =  $revenueYesterday;
		$view->countYesterday = $countYesterday;
                $view->marginYesterday = $marginYesterday;
		$view->revenueToday =  $revenueToday;
		$view->countToday = $countToday;
                $view->marginToday = $marginToday;
		$this->setGeneralVariablesView($view);
		echo $view->render();
		
	}

        
	/*
	 * See the result on piwik/?module=OxidPlugin&action=liveRevenuewWidget 
	 * or in the dashboard > Add a new widget. 
	 * This widget shows a table showing one line for each order
	 */
	function liveRevenueWidget()
	{
		include PIWIK_INCLUDE_PATH . '/plugins/OxidPlugin/conf/'.'config.inc.php';

                $this->SiteID = Piwik_Common::getRequestVar('idSite');
		$db = openDB($this);
				
		$siteCurrency = Piwik::getCurrency(Piwik_Common::getRequestVar('idSite'));
		
                $view = Piwik_ViewDataTable::factory('table');
                $view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getLiveRevenue' );

                $cols = array('oxbillname', 'orderdate', 'ordertime', 'oxtotalordersum');
                $view->setColumnsToDisplay($cols);
                $view->setColumnTranslation('oxbillname', Piwik_Translate('OxidPlugin_Name'));
                $view->setColumnTranslation('orderdate', Piwik_Translate('OxidPlugin_Date'));
                $view->setColumnTranslation('ordertime', Piwik_Translate('OxidPlugin_Time'));
                //$view->setColumnTranslation('paydesc', Piwik_Translate('OxidPlugin_PayType'));
                $view->setColumnTranslation('oxtotalordersum', Piwik_Translate('OxidPlugin_OrderSum'));
                //$view->setColumnTranslation('oxdiscount', Piwik_Translate('OxidPlugin_Discount'));
                //$view->setColumnTranslation('cancshare', Piwik_Translate('OxidPlugin_Percentage'));
                //$view->setColumnTranslation('cancpercent', Piwik_Translate('OxidPlugin_StornoPercentage'));
                $view->setSortedColumn('oxordernr', 'asc');

                $view->setLimit( 5 );
                $view->disableExcludeLowPopulation();
                //$view->disableFooterIcons();
                $view->alwaysShowLimitDropdown();
                $view->showLimitDropdown();
                $view->disableSearchBox();
                $view->disableRowEvolution();
                // hide metrics icons
                $view->disableShowAllColumns();
                // hide all chart icons
                $view->disableShowAllViewsIcons();
                $view->disableSort();
                $linkText = ' <a href="javascript:broadcast.propagateAjax(\'module=OxidPlugin&action=oxidMenuRevenue\')">'
                            . Piwik_Translate('OxidPlugin_oxidWidgets') . ' - ' . Piwik_Translate('OxidPlugin_Revenue')
                            . '</a>';
                $view->setFooterMessage(Piwik_Translate('General_GoTo', $linkText));

                return $this->renderView($view);
                
	}

        
	/*
	 * See the result on piwik/?module=OxidPlugin&action=revenuewAlertWidget 
	 * or in the dashboard > Add a new widget. 
	 * This widget shows the manufacturer with the biggest revenue loss in the last 30 days
	 */
	function revenueAlertWidget()
	{
		include PIWIK_INCLUDE_PATH . '/plugins/OxidPlugin/conf/'.'config.inc.php';

                $this->SiteID = Piwik_Common::getRequestVar('idSite');
		$db = openDB($this);
				
		$siteCurrency = Piwik::getCurrency(Piwik_Common::getRequestVar('idSite'));
		
                $view = Piwik_ViewDataTable::factory('table');
                $view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getRevenueAlerts' );

                $view->setColumnsToDisplay( array('title', 'longrev', 'shortrev', 'missedtext', 'evolutiontext') );
                //$view->setColumnsToDisplay($cols);
                $view->setColumnTranslation('title', Piwik_Translate('OxidPlugin_Manufacturer'));
                $view->setColumnTranslation('longrev', Piwik_Translate('OxidPlugin_LastXDays',180));
                $view->setColumnTranslation('shortrev', Piwik_Translate('OxidPlugin_LastXDays',30));
                //$view->setColumnTranslation('paydesc', Piwik_Translate('OxidPlugin_PayType'));
                $view->setColumnTranslation('missedtext', Piwik_Translate('OxidPlugin_OrderSum'));
                $view->setColumnTranslation('evolutiontext', Piwik_Translate('OxidPlugin_OrderSum'));
                //$view->setColumnTranslation('oxdiscount', Piwik_Translate('OxidPlugin_Discount'));
                //$view->setColumnTranslation('cancshare', Piwik_Translate('OxidPlugin_Percentage'));
                //$view->setColumnTranslation('cancpercent', Piwik_Translate('OxidPlugin_StornoPercentage'));
                $view->setSortedColumn('missed', 'asc');

                $view->setLimit( 5 );
                $view->disableExcludeLowPopulation();
                //$view->disableFooterIcons();
                $view->alwaysShowLimitDropdown();
                $view->showLimitDropdown();
                $view->disableSearchBox();
                $view->disableRowEvolution();
                // hide metrics icons
                $view->disableShowAllColumns();
                // hide all chart icons
                $view->disableShowAllViewsIcons();
                //$view->disableSort();
                $linkText = ' <a href="javascript:broadcast.propagateAjax(\'module=OxidPlugin&action=oxidMenuRevenue\')">'
                            . Piwik_Translate('OxidPlugin_oxidWidgets') . ' - ' . Piwik_Translate('OxidPlugin_Revenue')
                            . '</a>';
                $view->setFooterMessage(Piwik_Translate('General_GoTo', $linkText));

                return $this->renderView($view);
                
	}

        
	/*
	 * See the result on piwik/?module=OxidPlugin&action=birthdayWidget 
	 * or in the dashboard > Add a new widget. 
	 * This widget shows all customer have their birthday today
	 */
	function birthdayWidget()
	{
		include PIWIK_INCLUDE_PATH . '/plugins/OxidPlugin/conf/'.'config.inc.php';

                $this->SiteID = Piwik_Common::getRequestVar('idSite');
		$db = openDB($this);
				
		$siteCurrency = Piwik::getCurrency(Piwik_Common::getRequestVar('idSite'));
		
                $view = Piwik_ViewDataTable::factory('table');
                $view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getBirthdayUsers' );

                $cols = array('username', 'userage', 'ordercount', 'ordersum');
                $view->setColumnsToDisplay($cols);
                $view->setColumnTranslation('username', Piwik_Translate('OxidPlugin_Name'));
                $view->setColumnTranslation('userage', Piwik_Translate('OxidPlugin_Age'));
                $view->setColumnTranslation('ordercount', Piwik_Translate('OxidPlugin_Orders'));
                $view->setColumnTranslation('ordersum', Piwik_Translate('OxidPlugin_Sum'));
                
                $view->setSortedColumn('username', 'asc');

                $view->setLimit( 5 );
                $view->disableExcludeLowPopulation();
                // hide goals and metrics icons
                $view->disableShowAllColumns();
                //$view->disableFooterIcons();
                $view->disableShowAllViewIcons();
                $view->alwaysShowLimitDropdown();
                //$view->showLimitDropdown();
                $view->disableSearchBox();
                $view->disableRowEvolution();
                // hide all chart icons
                $view->disableShowAllViewsIcons();
                $view->disableShowExportAsRssFeed();  

                return $this->renderView($view);

	}

        
	/*
	 * See the result on piwik/?module=OxidPlugin&action=logisticsWidget 
	 * or in the dashboard > Add a new widget. 
	 * This widget shows a comparison of the orders and shipping in the last 30 and 60 days
	 */
	function logisticsWidget()
	{
            include PIWIK_INCLUDE_PATH . '/plugins/OxidPlugin/conf/'.'config.inc.php';

            $this->SiteID = Piwik_Common::getRequestVar('idSite');
            $date = Piwik_Common::getRequestVar('date');
            $db = openDB($this);

            $siteCurrency = Piwik::getCurrency(Piwik_Common::getRequestVar('idSite'));
            $period = Piwik_Common::getRequestVar('period');
            
            if ($period == 'range') {
                $dateStart = substr($date, 0, strpos($date, ',')); 
                $dateEnd = substr($date, strpos($date, ',')+1);  
            } else {
                $requestedDate = Piwik_Date::factory($date);
                $requestedPeriod = Piwik_Period::factory($period, $requestedDate);
                $dateStart = $requestedPeriod->getDateStart()->toString('Y-m-d'); 
                $dateEnd = $requestedPeriod->getDateEnd()->toString('Y-m-d');   
            }

            $dateThisStart = $dateStart;
            $dateThisEnd = $dateEnd;
            if ($this->LogisticsRange[$this->SiteID] == "last30") {
                $period = $this->LogisticsRange[$this->SiteID];
                $dateThisStart = date("Y-m-d",time()-3600*24*30);
                $dateThisEnd = date("Y-m-d",time()); //$dateStart;
            }
            
            $dayDiff = (int) ((strtotime($dateThisEnd) - strtotime($dateThisStart)) / 86400 +1);
            $datePrevStart = date("Y-m-d",strtotime($dateThisStart)-3600*24*$dayDiff);
            $datePrevEnd = date("Y-m-d",strtotime($dateThisEnd)-3600*24*$dayDiff);
            /*
            echo "period=".$period."<br>";
            echo "dateThisStart=".$dateThisStart."<br>";
            echo "dateThisEnd=".$dateThisEnd."<br>";
            echo "datePrevStart=".$datePrevStart."<br>";
            echo "datePrevEnd=".$datePrevEnd."<br>";
            echo "diff=".$dayDiff."<br>";
            */

            $whereThis = "DATE(oxorderdate) >= '$dateThisStart' AND DATE(oxorderdate) <= '$dateThisEnd' ";
            $wherePrev = "DATE(oxorderdate) >= '$datePrevStart' AND DATE(oxorderdate) <= '$datePrevEnd' ";

            $selSql = "SELECT COUNT(*) AS totalnum "
                     . "FROM oxorder "
                     . "WHERE oxstorno = 0 "
                        . "AND oxtotalordersum != 0.0 "
                        . 'AND oxshopid = ' . $this->ShopID[$this->SiteID] . ' '
                        . "AND ";
                
            $sql = $selSql . $whereThis;
            $result = $db->query($sql);
            $data = $result->fetch(PDO::FETCH_ASSOC);
            $countThisOrder = $data['totalnum'];
            
            $sql = str_replace('oxorderdate', 'oxsenddate', $sql);
            $result = $db->query($sql);
            $data = $result->fetch(PDO::FETCH_ASSOC);
            $countThisSent = $data['totalnum'];
            
            $sql = $selSql . $wherePrev;
            $result = $db->query($sql);
            $data = $result->fetch(PDO::FETCH_ASSOC);
            $countPrevOrder = $data['totalnum'];
            
            $sql = str_replace('oxorderdate', 'oxsenddate', $sql);
            $result = $db->query($sql);
            $data = $result->fetch(PDO::FETCH_ASSOC);
            $countPrevSent = $data['totalnum'];
            
            $sql = "SELECT COUNT(*) AS countready, SUM(oxtotalordersum) AS sumready "
                . "FROM oxorder "
                . "WHERE "
                    . "((oxpaid != '0000-00-00 00:00:00') "
                        ."OR (oxpaymenttype IN ('oxidinvoice',".$this->PaymentLater[$this->SiteID]."))) "
                    . 'AND oxshopid = ' . $this->ShopID[$this->SiteID] . ' '
                    . "AND oxsenddate = '0000-00-00 00:00:00' "
                    . "AND oxstorno = 0 ";
            $sql = $sql . ' AND ' . $whereThis;
            $result = $db->query($sql);
            $data = $result->fetch(PDO::FETCH_ASSOC);
            $countReady = $data['countready'];
            $sumReady = $data['sumready'];

            $db = null;

            $view = Piwik_View::factory('eshopLogistics');
            $view->siteCurrency = $siteCurrency;
            $view->period = $period;
            //$view->data = $data;
            $view->countThisOrder = $countThisOrder;
            $view->countPrevOrder = $countPrevOrder;
            $view->countThisSent = $countThisSent;
            $view->countPrevSent = $countPrevSent;
            $view->countReady = $countReady;
            $view->sumReady = $sumReady;
            echo $view->render();
	}

        
	/*
	 * See the result on piwik/?module=OxidPlugin&action=feedbackWidget 
	 * or in the dashboard > Add a new widget. 
	 * This widget shows all customer have their birthday today
	 */
	function feedbackWidget()
	{
		include PIWIK_INCLUDE_PATH . '/plugins/OxidPlugin/conf/'.'config.inc.php';
				
		$siteCurrency = Piwik::getCurrency(Piwik_Common::getRequestVar('idSite'));
                $this->SiteID = Piwik_Common::getRequestVar('idSite');

                $view = Piwik_ViewDataTable::factory('table');
                $view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getFeedbackList' );

                $cols = array('senddate', 'days', 'orderno', 'name', 'ordersum');
                $view->setColumnsToDisplay($cols);
                $view->setColumnTranslation('senddate', Piwik_Translate('OxidPlugin_SendDate'));
                $view->setColumnTranslation('days', Piwik_Translate('OxidPlugin_Days'));
                $view->setColumnTranslation('orderno', Piwik_Translate('OxidPlugin_OrderNo'));
                $view->setColumnTranslation('name', Piwik_Translate('OxidPlugin_Name'));
                $view->setColumnTranslation('ordersum', Piwik_Translate('OxidPlugin_OrderSum'));
                $view->setSortedColumn('senddate', 'asc');

                $view->setLimit( 5 );
                $view->disableExcludeLowPopulation();
                //$view->disableFooterIcons();
                $view->alwaysShowLimitDropdown();
                $view->showLimitDropdown();
                $view->disableSearchBox();
                $view->disableRowEvolution();
                // hide metrics icons
                $view->disableShowAllColumns();
                // hide all chart icons
                $view->disableShowAllViewsIcons();
                $view->disableShowExportAsRssFeed();
                $linkText = ' <a href="javascript:broadcast.propagateAjax(\'module=OxidPlugin&action=oxidMenuFeedbackList\')">'
                            . Piwik_Translate('OxidPlugin_oxidWidgets') . ' - ' . Piwik_Translate('OxidPlugin_Feedback')
                            . '</a>';
                $view->setFooterMessage(Piwik_Translate('General_GoTo', $linkText));
                
                return $this->renderView($view);

	}

        
	/*
	 * See the result on piwik/?module=OxidPlugin&action=voucherUseWidget 
	 * or in the dashboard > Add a new widget. 
	 * This widget shows all customer have their birthday today
	 */
	function voucherUseWidget()
	{
		include PIWIK_INCLUDE_PATH . '/plugins/OxidPlugin/conf/'.'config.inc.php';
				
		$siteCurrency = Piwik::getCurrency(Piwik_Common::getRequestVar('idSite'));
                $this->SiteID = Piwik_Common::getRequestVar('idSite');

                $view = Piwik_ViewDataTable::factory('table');
                $view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getVoucherUse' );

                $cols = array('name', 'days', 'oxordernr', 'oxtotalordersum', 'oxvouchernr', 'oxdiscount');
                $view->setColumnsToDisplay($cols);
                $view->setColumnTranslation('name', Piwik_Translate('OxidPlugin_Name'));
                $view->setColumnTranslation('days', Piwik_Translate('OxidPlugin_Days'));
                $view->setColumnTranslation('oxordernr', Piwik_Translate('OxidPlugin_OrderNo'));
                $view->setColumnTranslation('oxtotalordersum', Piwik_Translate('OxidPlugin_OrderSum'));
                $view->setColumnTranslation('oxvouchernr', Piwik_Translate('OxidPlugin_Voucher'));
                $view->setColumnTranslation('oxdiscount', Piwik_Translate('OxidPlugin_Discount'));
                //$view->setColumnTranslation('cancshare', Piwik_Translate('OxidPlugin_Percentage'));
                //$view->setColumnTranslation('cancpercent', Piwik_Translate('OxidPlugin_StornoPercentage'));
                $view->setSortedColumn('days', 'asc');

                $view->setLimit( 5 );
                $view->disableExcludeLowPopulation();
                //$view->disableFooterIcons();
                $view->alwaysShowLimitDropdown();
                $view->showLimitDropdown();
                $view->disableSearchBox();
                $view->disableRowEvolution();
                // hide metrics icons
                $view->disableShowAllColumns();
                // hide all chart icons
                $view->disableShowAllViewsIcons();
                $view->disableShowExportAsRssFeed();
                
                return $this->renderView($view);

	}

        
	/*
	 * See the result on piwik/?module=OxidPlugin&action=voucherOverviewWidget 
	 * or in the dashboard > Add a new widget. 
	 * This widget shows all customer have their birthday today
	 */
	function voucherOverviewWidget()
	{
		include PIWIK_INCLUDE_PATH . '/plugins/OxidPlugin/conf/'.'config.inc.php';
				
		$siteCurrency = Piwik::getCurrency(Piwik_Common::getRequestVar('idSite'));
                $this->SiteID = Piwik_Common::getRequestVar('idSite');

                $view = Piwik_ViewDataTable::factory('table');
                $view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getVoucherOverview' );

                $cols = array('oxvouchernr', 'usedcount', 'totalcount', 'days', 'ordersum', 'oxdiscount');
                $view->setColumnsToDisplay($cols);
                $view->setColumnTranslation('oxvouchernr', Piwik_Translate('OxidPlugin_Voucher'));
                $view->setColumnTranslation('usedcount', Piwik_Translate('OxidPlugin_Used'));
                $view->setColumnTranslation('totalcount', Piwik_Translate('OxidPlugin_Total'));
                $view->setColumnTranslation('days', Piwik_Translate('OxidPlugin_Days'));
                $view->setColumnTranslation('ordersum', Piwik_Translate('OxidPlugin_OrderSum'));
                $view->setColumnTranslation('oxdiscount', Piwik_Translate('OxidPlugin_Discount'));
                //$view->setColumnTranslation('cancshare', Piwik_Translate('OxidPlugin_Percentage'));
                //$view->setColumnTranslation('cancpercent', Piwik_Translate('OxidPlugin_StornoPercentage'));
                $view->setSortedColumn('usedcount', 'desc');

                $view->setLimit( 5 );
                $view->disableExcludeLowPopulation();
                //$view->disableFooterIcons();
                $view->alwaysShowLimitDropdown();
                $view->showLimitDropdown();
                $view->disableSearchBox();
                $view->disableRowEvolution();
                // hide metrics icons
                $view->disableShowAllColumns();
                // hide all chart icons
                $view->disableShowAllViewsIcons();
                $view->disableShowExportAsRssFeed();
                
                return $this->renderView($view);

	}

        
	/*
	 * See the result on piwik/?module=OxidPlugin&action=ppnotpaidWidget 
	 * or in the dashboard > Add a new widget. 
	 * This widget shows all customer have their birthday today
	 */
	function ppnotpaidWidget()
	{
		include PIWIK_INCLUDE_PATH . '/plugins/OxidPlugin/conf/'.'config.inc.php';

                $this->SiteID = Piwik_Common::getRequestVar('idSite');
                $db = openDB($this);
				
		$siteCurrency = Piwik::getCurrency(Piwik_Common::getRequestVar('idSite'));
		
                $view = Piwik_ViewDataTable::factory('table');
                $view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getOpenPayInAdvance' );

                $cols = array('days', 'oxordernr', 'oxtotalordersum', 'oxbillname', 'oxbilladdress');
                $view->setColumnsToDisplay($cols);
                $view->setColumnTranslation('days', Piwik_Translate('OxidPlugin_Days'));
                $view->setColumnTranslation('oxordernr', Piwik_Translate('OxidPlugin_OrderNo'));
                $view->setColumnTranslation('oxtotalordersum', Piwik_Translate('OxidPlugin_OrderSum'));
                $view->setColumnTranslation('oxbillname', Piwik_Translate('OxidPlugin_Name'));
                $view->setColumnTranslation('oxbilladdress', Piwik_Translate('OxidPlugin_City'));
                $view->setTooltipMetadataName('oxdetails');
                
                $view->setSortedColumn('days', 'asc');

                $view->setLimit( 5 );
                $view->disableExcludeLowPopulation();
                // hide goals and metrics icons
                $view->disableShowAllColumns();
                //$view->disableFooterIcons();
                $view->disableShowAllViewIcons();
                $view->alwaysShowLimitDropdown();
                //$view->showLimitDropdown();
                $view->disableSearchBox();
                $view->disableRowEvolution();
                // hide all chart icons
                $view->disableShowAllViewsIcons();
                $view->disableShowExportAsRssFeed();  
                $view->disableShowExportAsRssFeed();                
                $linkText = ' <a href="javascript:broadcast.propagateAjax(\'module=OxidPlugin&action=oxidMenuCIAnotPaid\')">'
                            . Piwik_Translate('OxidPlugin_oxidWidgets') . ' - ' . Piwik_Translate('OxidPlugin_CIAnotPaid')
                            . '</a>';
                $view->setFooterMessage(Piwik_Translate('General_GoTo', $linkText));

                return $this->renderView($view);
	}

	
	/*
	 * See the result on piwik/?module=OxidPlugin&action=codnotpaidWidget 
	 * or in the dashboard > Add a new widget. 
	 * This widget shows all customer have their birthday today
	 */
	function codnotpaidWidget()
	{
		include PIWIK_INCLUDE_PATH . '/plugins/OxidPlugin/conf/'.'config.inc.php';
				
		$siteCurrency = Piwik::getCurrency(Piwik_Common::getRequestVar('idSite'));
                $this->SiteID = Piwik_Common::getRequestVar('idSite');
		
                $view = Piwik_ViewDataTable::factory('table');
                $view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getOpenCashOnDelivery' );

                $cols = array('days', 'oxordernr', 'oxtotalordersum', 'oxbillname', 'oxbilladdress');
                $view->setColumnsToDisplay($cols);
                $view->setColumnTranslation('days', Piwik_Translate('OxidPlugin_Days'));
                $view->setColumnTranslation('oxordernr', Piwik_Translate('OxidPlugin_OrderNo'));
                $view->setColumnTranslation('oxtotalordersum', Piwik_Translate('OxidPlugin_OrderSum'));
                $view->setColumnTranslation('oxbillname', Piwik_Translate('OxidPlugin_Name'));
                $view->setColumnTranslation('oxbilladdress', Piwik_Translate('OxidPlugin_City'));
                $view->setTooltipMetadataName('oxdetails');
                
                $view->setSortedColumn('days', 'asc');

                $view->setLimit( 5 );
                $view->disableExcludeLowPopulation();
                // hide goals and metrics icons
                $view->disableShowAllColumns();
                //$view->disableFooterIcons();
                $view->disableShowAllViewIcons();
                $view->alwaysShowLimitDropdown();
                //$view->showLimitDropdown();
                $view->disableSearchBox();
                $view->disableRowEvolution();
                // hide all chart icons
                $view->disableShowAllViewsIcons();
                $view->disableShowExportAsRssFeed();  
                $view->disableShowExportAsRssFeed();
                if ( $this->ShowLinkToReport[$this->SiteID] ) {
                    $linkText = ' <a href="javascript:broadcast.propagateAjax(\'module=OxidPlugin&action=oxidMenuCODnotReceived\')">'
                                . Piwik_Translate('OxidPlugin_oxidWidgets') . ' - ' . Piwik_Translate('OxidPlugin_CODnotReceived')
                                . '</a>';
                    $view->setFooterMessage(Piwik_Translate('General_GoTo', $linkText));
                }

                return $this->renderView($view);

	}
	
	
	/*
	 * See the result on piwik/?module=OxidPlugin&action=invoicenotpaidWidget 
	 * or in the dashboard > Add a new widget. 
	 * This widget shows all customer have their birthday today
	 */
	function invoicenotpaidWidget()
	{
		include PIWIK_INCLUDE_PATH . '/plugins/OxidPlugin/conf/'.'config.inc.php';
				
		$siteCurrency = Piwik::getCurrency(Piwik_Common::getRequestVar('idSite'));
                $this->SiteID = Piwik_Common::getRequestVar('idSite');
		
                $view = Piwik_ViewDataTable::factory('table');
                $view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getOpenInvoices' );

                $cols = array('days', 'oxordernr', 'oxtotalordersum', 'oxbillname', 'oxbilladdress');
                $view->setColumnsToDisplay($cols);
                $view->setColumnTranslation('days', Piwik_Translate('OxidPlugin_Days'));
                $view->setColumnTranslation('oxordernr', Piwik_Translate('OxidPlugin_OrderNo'));
                $view->setColumnTranslation('oxtotalordersum', Piwik_Translate('OxidPlugin_OrderSum'));
                $view->setColumnTranslation('oxbillname', Piwik_Translate('OxidPlugin_Name'));
                $view->setColumnTranslation('oxbilladdress', Piwik_Translate('OxidPlugin_City'));
                $view->setTooltipMetadataName('oxdetails');
                
                $view->setSortedColumn('days', 'asc');

                $view->setLimit( 5 );
                $view->disableExcludeLowPopulation();
                // hide goals and metrics icons
                $view->disableShowAllColumns();
                //$view->disableFooterIcons();
                $view->disableShowAllViewIcons();
                $view->alwaysShowLimitDropdown();
                //$view->showLimitDropdown();
                $view->disableSearchBox();
                $view->disableRowEvolution();
                // hide all chart icons
                $view->disableShowAllViewsIcons();
                $view->disableShowExportAsRssFeed();  
                $linkText = ' <a href="javascript:broadcast.propagateAjax(\'module=OxidPlugin&action=oxidMenuInvoiceNotPaid\')">'
                            . Piwik_Translate('OxidPlugin_oxidWidgets') . ' - ' . Piwik_Translate('OxidPlugin_InvoiceNotPaid')
                            . '</a>';
                $view->setFooterMessage(Piwik_Translate('General_GoTo', $linkText));

                return $this->renderView($view);

	}
	
	
	/*
	 * See the result on piwik/?module=OxidPlugin&action=paytypesWidget 
	 * or in the dashboard > Add a new widget. 
	 * This widget shows all customer have their birthday today
	 */
	function paytypeSumsWidget()
	{
		include PIWIK_INCLUDE_PATH . '/plugins/OxidPlugin/conf/'.'config.inc.php';

                $this->SiteID = Piwik_Common::getRequestVar('idSite');

                $view = Piwik_ViewDataTable::factory('table');
                $view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getPayTypeSums' );

                $cols = array('oxdesc', 'ordercount', 'totalordersum', 'percentage');
                $view->setColumnsToDisplay($cols);
                $view->setColumnTranslation('oxdesc', Piwik_Translate('OxidPlugin_PayType'));
                $view->setColumnTranslation('ordercount', Piwik_Translate('OxidPlugin_Count'));
                $view->setColumnTranslation('totalordersum', Piwik_Translate('OxidPlugin_OrderSum'));
                $view->setColumnTranslation('percentage', Piwik_Translate('OxidPlugin_Percentage'));
                
                $view->setSortedColumn('oxdesc', 'asc');

                $view->setLimit( 10 );
                $view->disableExcludeLowPopulation();
                // hide goals and metrics icons
                $view->disableShowAllColumns();
                //$view->disableFooterIcons();
                $view->disableShowAllViewIcons();
                $view->alwaysShowLimitDropdown();
                //$view->showLimitDropdown();
                $view->disableSearchBox();
                $view->disableRowEvolution();
                // hide all chart icons
                $view->disableShowAllViewsIcons();
                $view->disableShowExportAsRssFeed();  
                $view->disableShowExportAsRssFeed();
                /*
                $linkText = ' <a href="javascript:broadcast.propagateAjax(\'module=OxidPlugin&action=oxidMenuInvoiceNotPaid\')">'
                            . Piwik_Translate('OxidPlugin_oxidWidgets') . ' - ' . Piwik_Translate('OxidPlugin_InvoiceNotPaid')
                            . '</a>';
                $view->setFooterMessage(Piwik_Translate('General_GoTo', $linkText));
                */

                return $this->renderView($view);

	}
	
	
	/*
	 * See the result on piwik/?module=OxidPlugin&action=birtdayWidget 
	 * or in the dashboard > Add a new widget. 
	 * This widget shows all customer have their birthday today
	 */
	function paymentWidget()
	{
		include PIWIK_INCLUDE_PATH . '/plugins/OxidPlugin/conf/'.'config.inc.php';
				
		$siteCurrency = Piwik::getCurrency(Piwik_Common::getRequestVar('idSite'));
                $this->SiteID = Piwik_Common::getRequestVar('idSite');
		$db = openDB($this);
		
		// select open CIA
		$sql = 'SELECT count(*) AS totalnum, sum(oxtotalordersum) AS totalsum '
			 . 'FROM oxorder '
			 . 'WHERE oxpaymenttype = '.$this->PaymentCIA[$this->SiteID].' '
                         . 'AND oxshopid = ' . $this->ShopID[$this->SiteID] . ' '
			 . 'AND oxpaid = \'0000-00-00 00:00:00\' '
			 . 'AND oxstorno = 0 '; 
		$result = $db->query($sql);
		$data = $result->fetch(PDO::FETCH_ASSOC);
		$countCIA = $data['totalnum'];
		$openCIA = 0.0 - $data['totalsum'];
		
		// select open COD
		$sql = 'SELECT count(*) AS totalnum, sum(oxtotalordersum) AS totalsum '
			 . 'FROM oxorder '
			 . 'WHERE oxpaymenttype = '.$this->PaymentCOD[$this->SiteID].' '
                         . 'AND oxshopid = ' . $this->ShopID[$this->SiteID] . ' '
			 . 'AND oxpaid = \'0000-00-00 00:00:00\' '
			 . 'AND oxsenddate != \'0000-00-00 00:00:00\' '
			 . 'AND oxstorno = 0 '; 
		$result = $db->query($sql);
		$data = $result->fetch(PDO::FETCH_ASSOC);
		$countCOD = $data['totalnum'];
		$openCOD = 0.0 - $data['totalsum'];
			
		// select Invoices
		$sql = 'SELECT count(*) AS totalnum, sum(oxtotalordersum) AS totalsum '
			 . 'FROM oxorder '
			 . 'WHERE oxpaymenttype IN ('.$this->PaymentInvoice[$this->SiteID].') '
                         . 'AND oxshopid = ' . $this->ShopID[$this->SiteID] . ' '
			 . 'AND oxpaid = \'0000-00-00 00:00:00\' '
			 . 'AND oxsenddate != \'0000-00-00 00:00:00\' '
			 . 'AND oxstorno = 0 '; 
		$result = $db->query($sql);
		$data = $result->fetch(PDO::FETCH_ASSOC);
		$countInvoices = $data['totalnum'];
		$openInvoices = 0.0 - $data['totalsum'];
			
		// select PrePaid
		$sql = 'SELECT count(*) AS totalnum, sum(oxtotalordersum) AS totalsum '
			 . 'FROM oxorder '
			 . 'WHERE oxpaid != \'0000-00-00 00:00:00\' '
			 . 'AND oxsenddate = \'0000-00-00 00:00:00\' '
                         . 'AND oxshopid = ' . $this->ShopID[$this->SiteID] . ' '
			 . 'AND oxstorno = 0 '; 
		$result = $db->query($sql);
		$data = $result->fetch(PDO::FETCH_ASSOC);
		$countPrepaid = $data['totalnum'];
		$openPrepaid = 0.0 + $data['totalsum'];
			
		$db = null;
		
		$view = Piwik_View::factory('eshopPayments');
		$view->siteCurrency = $siteCurrency;
                
                $linkText = ' <a href="javascript:broadcast.propagateAjax(\'module=OxidPlugin&action=oxidMenuRevenue\')">'
                            . Piwik_Translate('OxidPlugin_oxidWidgets') . ' - ' . Piwik_Translate('OxidPlugin_Revenue')
                            . '</a>';
                $view->footerMessage = Piwik_Translate('General_GoTo', $linkText);
                
		$view->countCIA =  $countCIA;
		$view->openCIA =  $openCIA;
		$view->countCOD =  $countCOD;
		$view->openCOD =  $openCOD;
		$view->countInvoices =  $countInvoices;
		$view->openInvoices =  $openInvoices;
		$view->countPrepaid =  $countPrepaid;
		$view->openPrepaid =  $openPrepaid;
		$this->setGeneralVariablesView($view);
		echo $view->render();
		
	}

	
	/*
	 * See the result on piwik/?module=OxidPlugin&action=newsregWidget 
	 * or in the dashboard > Add a new widget. 
	 * This widget shows the newest newsletter registrations
	 */
	function rateandreviewWidget()
	{
		include PIWIK_INCLUDE_PATH . '/plugins/OxidPlugin/conf/'.'config.inc.php';
				
		$siteCurrency = Piwik::getCurrency(Piwik_Common::getRequestVar('idSite'));
                $this->SiteID = Piwik_Common::getRequestVar('idSite');

                $view = Piwik_ViewDataTable::factory('table');
                $view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getRatingsAndReviews' );

                $cols = array('oxtitle', 'oxdays', 'shorttext', 'oxrating');
                $view->setColumnsToDisplay($cols);
                $view->setColumnTranslation('oxdays', Piwik_Translate('OxidPlugin_Days'));
                $view->setColumnTranslation('oxtitle', Piwik_Translate('OxidPlugin_ArtTitle'));
                $view->setColumnTranslation('shorttext', Piwik_Translate('OxidPlugin_Remark'));
                $view->setColumnTranslation('oxrating', Piwik_Translate('OxidPlugin_Rating'));
                $view->setSortedColumn('oxdays', 'asc');

                $view->setLimit( 5 );
                $view->disableExcludeLowPopulation();
                //$view->disableFooterIcons();
                $view->alwaysShowLimitDropdown();
                $view->showLimitDropdown();
                $view->disableSearchBox();
                $view->disableRowEvolution();
                // hide metrics icons
                $view->disableShowAllColumns();
                // hide all chart icons
                $view->disableShowAllViewsIcons();
                //$view->disableSort();
                $view->disableShowExportAsRssFeed();
                
                return $this->renderView($view);
                
	}

	
	/*
	 * See the result on piwik/?module=OxidPlugin&action=newsregWidget 
	 * or in the dashboard > Add a new widget. 
	 * This widget shows the newest newsletter registrations
	 */
	function newsregWidget()
	{
		include PIWIK_INCLUDE_PATH . '/plugins/OxidPlugin/conf/'.'config.inc.php';
				
		$siteCurrency = Piwik::getCurrency(Piwik_Common::getRequestVar('idSite'));
                $this->SiteID = Piwik_Common::getRequestVar('idSite');
		$db = openDB($this);
		
                $view = Piwik_ViewDataTable::factory('table');
                $view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getNewsRegs' );

                $cols = array('oxname', 'oxdays', 'oxdboptin', 'ordercount', 'ordersum');
                $view->setColumnsToDisplay($cols);
                $view->setColumnTranslation('oxdays', Piwik_Translate('OxidPlugin_Days'));
                $view->setColumnTranslation('oxname', Piwik_Translate('OxidPlugin_Name'));
                $view->setColumnTranslation('oxdboptin', Piwik_Translate('OxidPlugin_State'));
                $view->setColumnTranslation('ordercount', Piwik_Translate('OxidPlugin_Count'));
                $view->setColumnTranslation('ordersum', Piwik_Translate('OxidPlugin_OrderSum'));
                $view->setSortedColumn('oxdays', 'asc');

                $view->setLimit( 5 );
                $view->disableExcludeLowPopulation();
                //$view->disableFooterIcons();
                $view->alwaysShowLimitDropdown();
                $view->showLimitDropdown();
                $view->disableSearchBox();
                $view->disableRowEvolution();
                // hide metrics icons
                $view->disableShowAllColumns();
                // hide all chart icons
                $view->disableShowAllViewsIcons();
                //$view->disableSort();
                $view->disableShowExportAsRssFeed();
                
                //echo $view->render();
                return $this->renderView($view);
		
	}

	
	/*
	 * See the result on piwik/?module=OxidPlugin&action=paytypesWidget 
	 * or in the dashboard > Add a new widget. 
	 * This widget shows all customer have their birthday today
	 */
	function userAgeWidget()
	{
		include PIWIK_INCLUDE_PATH . '/plugins/OxidPlugin/conf/'.'config.inc.php';
				
		$siteCurrency = Piwik::getCurrency(Piwik_Common::getRequestVar('idSite'));
		$selectedYear = date("Y", strtotime(Piwik_Common::getRequestVar('date')));
                $this->SiteID = Piwik_Common::getRequestVar('idSite');
		$db = openDB($this);
		
		$ageClasses = explode('|', $this->AgeClasses[$this->SiteID]);
		$data = array();
		
		$sql = array();
		$total = array();
                $andWhere = 'AND YEAR(u.oxbirthdate) != 0 '
                          . 'AND u.oxshopid = ' . $this->ShopID[$this->SiteID] . ' '; 

		array_push($sql, "SELECT COUNT(*) AS total FROM oxuser u " 
						. "WHERE u.oxsal = 'MR' ".$andWhere );
		array_push($sql, "SELECT COUNT(*) AS total FROM oxuser u " 
						. "WHERE u.oxsal = 'MRS' ".$andWhere );
		array_push($sql, "SELECT SUM(o.oxtotalordersum) AS total FROM oxuser u, oxorder o "
						. "WHERE  u.oxid = o.oxuserid AND u.oxsal = 'MR' ".$andWhere );
		array_push($sql, "SELECT SUM(o.oxtotalordersum) AS total FROM oxuser u, oxorder o "
						. "WHERE  u.oxid = o.oxuserid AND u.oxsal = 'MRS' ".$andWhere ) ;
		
		foreach ($sql as $stmt) {
			if ($this->DebugMode) logfile('debug', 'userAgeWidget: '.$stmt);
			$result = $db->query($stmt);
			$dbData = $result->fetch(PDO::FETCH_ASSOC);
			if (empty($dbData['total'])) $dbData['total'] = '1.0';
			array_push($total, $dbData['total']);
			if ($this->DebugMode) logfile('debug', $dbData);
		}
						
		foreach ($ageClasses as $ageClass) {
			$sql = array();
                        $andWhere = 'AND (YEAR(curdate())-YEAR(u.oxbirthdate)) BETWEEN ' . str_replace('-', ' AND ', $ageClass) . ' '
                                  . 'AND u.oxshopid = ' . $this->ShopID[$this->SiteID] . ' '; 
                        
			array_push($sql,  'SELECT COUNT(*) AS totalsum, COUNT(*)/'.$total[0].'*100.0 AS percent ' 
				 			. 'FROM oxuser u ' 
				 			. 'WHERE oxsal = \'MR\' ' 
							. $andWhere );
			array_push($sql,  'SELECT COUNT(*) AS totalsum, COUNT(*)/'.$total[1].'*100.0 AS percent ' 
				 			. 'FROM oxuser u ' 
				 			. 'WHERE oxsal = \'MRS\' ' 
							. $andWhere );
			array_push($sql,  'SELECT SUM(o.oxtotalordersum) AS totalsum, SUM(o.oxtotalordersum)/'.$total[2].'*100.0 AS percent '  
							. 'FROM oxuser u, oxorder o '
							. 'WHERE  u.oxid = o.oxuserid '
							. 'AND oxsal = \'MR\' ' 
							. $andWhere );
			array_push($sql,  'SELECT SUM(o.oxtotalordersum) AS totalsum, SUM(o.oxtotalordersum)/'.$total[3].'*100.0 AS percent '  
							. 'FROM oxuser u, oxorder o '
							. 'WHERE  u.oxid = o.oxuserid '
							. 'AND oxsal = \'MRS\' ' 
							. $andWhere );
							
			$percentage = array();
			foreach ($sql as $stmt) {
				$result = $db->query($stmt);
				$dbData = $result->fetch(PDO::FETCH_ASSOC);
				array_push($percentage, $dbData['percent']);
				if ($this->DebugMode) logfile('debug', 'userAgeWidget: '.$stmt);
				if ($this->DebugMode) logfile('debug', $dbData);
			}
							
			array_push($data, array('ageclass' => str_replace('-', '&nbsp;-&nbsp;', $ageClass), 
				'malecount' => $percentage[0], 
				'femalecount' => $percentage[1], 
				'malerevenue' => $percentage[2], 
				'femalerevenue' => $percentage[3]));
			
		}

		
		$db = null;
		
		$view = Piwik_View::factory('eshopAgeClasses');
		$view->siteCurrency = $siteCurrency;
		$view->data = $data;
		$this->setGeneralVariablesView($view);
		echo $view->render();

	}
	
	
	function oxidMenuRevenue()
	{
		$this->echoRevenueGraph();
		
		echo '<p>&nbsp;</p>';
		$view = Piwik_ViewDataTable::factory('table');
		$view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getRevenue' );
		
		$periodRange = Piwik_Common::getRequestVar('period');
		 
		switch ($periodRange) {
			case 'day':
			case 'range':
				$view->setColumnsToDisplay(array('dateval', 'count', 'custname', 'custdeladdr', 'average', 'netmargin', 'revsum', 'stornosum', 'payment', 'sendstate', 'remark'));
				$view->setColumnTranslation('dateval', Piwik_Translate('OxidPlugin_Time'));
				$view->setColumnTranslation('count', Piwik_Translate('OxidPlugin_OrderNo'));
				$view->setColumnTranslation('average', Piwik_Translate('OxidPlugin_ArtTitle'));
				$view->setColumnTranslation('custname', Piwik_Translate('OxidPlugin_Name'));
				$view->setColumnTranslation('custdeladdr', Piwik_Translate('OxidPlugin_City'));
				$view->setColumnTranslation('netmargin', Piwik_Translate('OxidPlugin_Margin'));
				$view->setColumnTranslation('revsum', Piwik_Translate('OxidPlugin_Revenue'));
				$view->setColumnTranslation('stornosum', Piwik_Translate('OxidPlugin_Storno'));
				$view->setColumnTranslation('payment', Piwik_Translate('OxidPlugin_Payment'));
				$view->setColumnTranslation('sendstate', Piwik_Translate('OxidPlugin_SendState'));
				$view->setColumnTranslation('remark', Piwik_Translate('OxidPlugin_Remark'));
				$view->setSortedColumn('dateval', 'desc');
				break;
			case 'week':
				$view->setColumnsToDisplay(array('dateval', 'count', 'average', 'revsum', 'netmargin', 'stornosum'));
				$view->setColumnTranslation('dateval', Piwik_Translate('OxidPlugin_Week'));
				$view->setColumnTranslation('count', Piwik_Translate('OxidPlugin_Count'));
				$view->setColumnTranslation('average', Piwik_Translate('OxidPlugin_Average'));
				$view->setColumnTranslation('revsum', Piwik_Translate('OxidPlugin_Revenue'));
				$view->setColumnTranslation('netmargin', Piwik_Translate('OxidPlugin_Margin'));
				$view->setColumnTranslation('stornosum', Piwik_Translate('OxidPlugin_Storno'));
				$view->setSortedColumn('dateval', 'desc');
				break;
			case 'month':
				$view->setColumnsToDisplay(array('dateval', 'count', 'average', 'revsum', 'netmargin', 'stornosum'));
				$view->setColumnTranslation('dateval', Piwik_Translate('OxidPlugin_Month'));
				$view->setColumnTranslation('count', Piwik_Translate('OxidPlugin_Count'));
				$view->setColumnTranslation('average', Piwik_Translate('OxidPlugin_Average'));
				$view->setColumnTranslation('revsum', Piwik_Translate('OxidPlugin_Revenue'));
				$view->setColumnTranslation('netmargin', Piwik_Translate('OxidPlugin_Margin'));
				$view->setColumnTranslation('stornosum', Piwik_Translate('OxidPlugin_Storno'));
				$view->setSortedColumn('dateval', 'desc');
				break;
			case 'year':
				$view->setColumnsToDisplay(array('dateval', 'count', 'average', 'revsum', 'netmargin', 'stornosum'));
				$view->setColumnTranslation('dateval', Piwik_Translate('OxidPlugin_Year'));
				$view->setColumnTranslation('count', Piwik_Translate('OxidPlugin_Count'));
				$view->setColumnTranslation('average', Piwik_Translate('OxidPlugin_Average'));
				$view->setColumnTranslation('revsum', Piwik_Translate('OxidPlugin_Revenue'));
				$view->setColumnTranslation('netmargin', Piwik_Translate('OxidPlugin_Margin'));
				$view->setColumnTranslation('stornosum', Piwik_Translate('OxidPlugin_Storno'));
				$view->setSortedColumn('dateval', 'desc');
				break;
		}
		$view->setLimit( 30 );
		$view->disableExcludeLowPopulation();
		$view->disableFooterIcons();
		$view->disableSearchBox();
                $view->disableRowEvolution();
		return $this->renderView($view);
	}
	
	
	function oxidMenuReadyToSend()
	{
		$view = Piwik_ViewDataTable::factory('table');
		$view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getReadyToSend' );
		
		$view->setColumnsToDisplay(array('days', 'orderdate', 'orderno', 'company', 'name', 'custdeladdr', 'orderlist', 'ordersum', 'paytype', 'remark'));
		$view->setColumnTranslation('days', Piwik_Translate('OxidPlugin_Days'));
		$view->setColumnTranslation('orderdate', Piwik_Translate('OxidPlugin_OrderDate'));
		$view->setColumnTranslation('orderno', Piwik_Translate('OxidPlugin_OrderNo'));
		$view->setColumnTranslation('company', Piwik_Translate('OxidPlugin_Company'));
		$view->setColumnTranslation('name', Piwik_Translate('OxidPlugin_Name'));
		$view->setColumnTranslation('custdeladdr', Piwik_Translate('OxidPlugin_City'));
		$view->setColumnTranslation('orderlist', Piwik_Translate('OxidPlugin_OrderList'));
		$view->setColumnTranslation('ordersum', Piwik_Translate('OxidPlugin_OrderSum'));
		$view->setColumnTranslation('paytype', Piwik_Translate('OxidPlugin_PayType'));
		$view->setColumnTranslation('remark', Piwik_Translate('OxidPlugin_Remark'));
		$view->setSortedColumn('days', 'asc');
		
		$view->setLimit( 30 );
		$view->disableExcludeLowPopulation();
		$view->disableFooterIcons();
		$view->disableSearchBox();
                $view->disableRowEvolution();
		return $this->renderView($view);
	}
	
	
	function oxidMenuFeedbackList()
	{
		$view = Piwik_ViewDataTable::factory('table');
		$view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getFeedbackList' );
		
		$view->setColumnsToDisplay(array('orderdate', 'days', 'senddate', 'orderno', 'trackcode', 'company', 'name', 'email', 'city', 'ordersum' ));
		$view->setColumnTranslation('orderdate', Piwik_Translate('OxidPlugin_OrderDate'));
		$view->setColumnTranslation('days', Piwik_Translate('OxidPlugin_Days'));
		$view->setColumnTranslation('senddate', Piwik_Translate('OxidPlugin_SendDate'));
		$view->setColumnTranslation('orderno', Piwik_Translate('OxidPlugin_OrderNo'));
		$view->setColumnTranslation('trackcode', Piwik_Translate('OxidPlugin_TrackingCode'));
		$view->setColumnTranslation('company', Piwik_Translate('OxidPlugin_Company'));
		$view->setColumnTranslation('name', Piwik_Translate('OxidPlugin_Name'));
		$view->setColumnTranslation('email', Piwik_Translate('OxidPlugin_EMail'));
		$view->setColumnTranslation('city', Piwik_Translate('OxidPlugin_City'));
		$view->setColumnTranslation('ordersum', Piwik_Translate('OxidPlugin_OrderSum'));
		$view->setSortedColumn('orderdate', 'asc');
		
		$view->setLimit( 30 );
		$view->disableExcludeLowPopulation();
		$view->disableFooterIcons();
		$view->disableSearchBox();
                $view->disableRowEvolution();
		return $this->renderView($view);
	}
	
	
	function oxidMenuCIAnotPaid()
	{
		$view = Piwik_ViewDataTable::factory('table');
		$view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getCIAnotPaid' );
		
		$view->setColumnsToDisplay(array('days', 'orderdate', 'orderno', 'company', 'name', 'custdeladdr', 'orderlist', 'ordersum', 'remark'));
		$view->setColumnTranslation('days', Piwik_Translate('OxidPlugin_Days'));
		$view->setColumnTranslation('orderdate', Piwik_Translate('OxidPlugin_OrderDate'));
		$view->setColumnTranslation('orderno', Piwik_Translate('OxidPlugin_OrderNo'));
		$view->setColumnTranslation('company', Piwik_Translate('OxidPlugin_Company'));
		$view->setColumnTranslation('name', Piwik_Translate('OxidPlugin_Name'));
		$view->setColumnTranslation('custdeladdr', Piwik_Translate('OxidPlugin_City'));
		$view->setColumnTranslation('orderlist', Piwik_Translate('OxidPlugin_OrderList'));
		$view->setColumnTranslation('ordersum', Piwik_Translate('OxidPlugin_OrderSum'));
		$view->setColumnTranslation('remark', Piwik_Translate('OxidPlugin_Remark'));
		$view->setSortedColumn('days', 'asc');
		
		$view->setLimit( 30 );
		$view->disableExcludeLowPopulation();
		$view->disableFooterIcons();
		$view->disableSearchBox();
                $view->disableRowEvolution();
		return $this->renderView($view);
	}
	
	
	function oxidMenuCODnotReceived()
	{
		$view = Piwik_ViewDataTable::factory('table');
		$view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getCODnotReceived' );
		
		$view->setColumnsToDisplay(array('days', 'senddate', 'orderno', 'trackcode', 'company', 'name', 'custdeladdr', 'orderlist', 'ordersum', 'remark'));
		$view->setColumnTranslation('days', Piwik_Translate('OxidPlugin_Days'));
		$view->setColumnTranslation('senddate', Piwik_Translate('OxidPlugin_SendDate'));
		$view->setColumnTranslation('orderno', Piwik_Translate('OxidPlugin_OrderNo'));
		$view->setColumnTranslation('trackcode', Piwik_Translate('OxidPlugin_TrackingCode'));
		$view->setColumnTranslation('company', Piwik_Translate('OxidPlugin_Company'));
		$view->setColumnTranslation('name', Piwik_Translate('OxidPlugin_Name'));
		$view->setColumnTranslation('custdeladdr', Piwik_Translate('OxidPlugin_City'));
		$view->setColumnTranslation('orderlist', Piwik_Translate('OxidPlugin_OrderList'));
		$view->setColumnTranslation('ordersum', Piwik_Translate('OxidPlugin_OrderSum'));
		$view->setColumnTranslation('remark', Piwik_Translate('OxidPlugin_Remark'));
		$view->setSortedColumn('days', 'asc');
		
		$view->setLimit( 30 );
		$view->disableExcludeLowPopulation();
		$view->disableFooterIcons();
		$view->disableSearchBox();
                $view->disableRowEvolution();
		return $this->renderView($view);
	}
	
	
	function oxidMenuInvoiceNotPaid()
	{
		$view = Piwik_ViewDataTable::factory('table');
		$view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getInvoiceNotPaid' );
		
		$view->setColumnsToDisplay(array('days', 'senddate', 'orderno', 'trackcode', 'company', 'name', 'custdeladdr', 'orderlist', 'ordersum', 'remark'));
		$view->setColumnTranslation('days', Piwik_Translate('OxidPlugin_Days'));
		$view->setColumnTranslation('senddate', Piwik_Translate('OxidPlugin_SendDate'));
		$view->setColumnTranslation('orderno', Piwik_Translate('OxidPlugin_OrderNo'));
		$view->setColumnTranslation('trackcode', Piwik_Translate('OxidPlugin_TrackingCode'));
		$view->setColumnTranslation('company', Piwik_Translate('OxidPlugin_Company'));
		$view->setColumnTranslation('name', Piwik_Translate('OxidPlugin_Name'));
		$view->setColumnTranslation('custdeladdr', Piwik_Translate('OxidPlugin_City'));
		$view->setColumnTranslation('orderlist', Piwik_Translate('OxidPlugin_OrderList'));
		$view->setColumnTranslation('ordersum', Piwik_Translate('OxidPlugin_OrderSum'));
		$view->setColumnTranslation('remark', Piwik_Translate('OxidPlugin_Remark'));
		$view->setSortedColumn('days', 'asc');
		
		$view->setLimit( 30 );
		$view->disableExcludeLowPopulation();
		$view->disableFooterIcons();
		$view->disableSearchBox();
                $view->disableRowEvolution();
		return $this->renderView($view);
	}
	
	
	function oxidMenuPaidInAdvance()
	{
		$view = Piwik_ViewDataTable::factory('table');
		$view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getPrePaid' );
		
		$view->setColumnsToDisplay(array('days', 'orderdate', 'orderno', 'company', 'name', 'custdeladdr', 'orderlist', 'ordersum', 'remark'));
		$view->setColumnTranslation('days', Piwik_Translate('OxidPlugin_Days'));
		$view->setColumnTranslation('orderdate', Piwik_Translate('OxidPlugin_OrderDate'));
		$view->setColumnTranslation('orderno', Piwik_Translate('OxidPlugin_OrderNo'));
		$view->setColumnTranslation('company', Piwik_Translate('OxidPlugin_Company'));
		$view->setColumnTranslation('name', Piwik_Translate('OxidPlugin_Name'));
		$view->setColumnTranslation('custdeladdr', Piwik_Translate('OxidPlugin_City'));
		//$view->setColumnTranslation('paytype', Piwik_Translate('OxidPlugin_PayType'));
		$view->setColumnTranslation('orderlist', Piwik_Translate('OxidPlugin_OrderList'));
		$view->setColumnTranslation('ordersum', Piwik_Translate('OxidPlugin_OrderSum'));
		$view->setColumnTranslation('remark', Piwik_Translate('OxidPlugin_Remark'));
		$view->setSortedColumn('days', 'asc');
		
		$view->setLimit( 30 );
		$view->disableExcludeLowPopulation();
		$view->disableFooterIcons();
		$view->disableSearchBox();
                $view->disableRowEvolution();
		return $this->renderView($view);
	}
	
	
	function oxidMenuTimeRevenue()
	{
            $view = Piwik_View::factory('eshopTimeRevenue');
            $view->daytimeRevenueGraph = $this->echoDaytimeRevenueGraph(true) ;
            //$view->weekdayRevenueGraph = $this->echoWeekdayRevenueGraph(true);
            $view->daytimeRevenueTable = $this->oxidGetDaytimeRevenue(true) ;
            $view->weekdayRevenueTable = $this->oxidGetWeekdayRevenue(true);
            echo $view->render();
	}
	
	

        
        function echoDaytimeRevenueGraph( $fetch = false )
	{
            
            $view = Piwik_ViewDataTable::factory('graphEvolution');
            $view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getDaytimeGraph' );
            
            $view->setColumnTranslation('revenue', Piwik_Translate('OxidPlugin_Revenue'));
            $view->setColumnTranslation('cancel', Piwik_Translate('OxidPlugin_Storno'));
            $view->setAxisYUnit(Piwik::getCurrency(Piwik_Common::getRequestVar('idSite')));
            return $this->renderView($view, $fetch);
            
	}
	
	
        function echoWeekdayRevenueGraph( $fetch = false )
	{

            $view = Piwik_ViewDataTable::factory('graphEvolution');
            $view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getWeekdayGraph' );
            
            $view->setColumnTranslation('revenue', Piwik_Translate('OxidPlugin_Revenue'));
            $view->setColumnTranslation('cancel', Piwik_Translate('OxidPlugin_Storno'));
            $view->setAxisYUnit(Piwik::getCurrency(Piwik_Common::getRequestVar('idSite')));
            return $this->renderView($view, $fetch);
            
	}

        
        
        function oxidGetDaytimeRevenue( $fetch = false )
	{

            $view = Piwik_ViewDataTable::factory('table');
            $view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getDaytimeAnalysis' );

            $cols = array('daytime', 'revenue', 'revshare', 'cancel', 'cancshare', 'cancpercent');
            $view->setColumnsToDisplay($cols);
            $view->setColumnTranslation('daytime', Piwik_Translate('OxidPlugin_Time'));
            $view->setColumnTranslation('revenue', Piwik_Translate('OxidPlugin_Revenue'));
            $view->setColumnTranslation('revshare', Piwik_Translate('OxidPlugin_Percentage'));
            $view->setColumnTranslation('cancel', Piwik_Translate('OxidPlugin_Storno'));
            $view->setColumnTranslation('cancshare', Piwik_Translate('OxidPlugin_Percentage'));
            $view->setColumnTranslation('cancpercent', Piwik_Translate('OxidPlugin_StornoPercentage'));
            $view->setSortedColumn('daytime', 'asc');

            $view->setLimit( 30 );
            $view->disableExcludeLowPopulation();
            $view->disableFooterIcons();
            $view->disableSearchBox();
            $view->disableRowEvolution();
            return $this->renderView($view, $fetch);
	}
	
	
	function oxidGetWeekdayRevenue( $fetch = false )
	{

            $view = Piwik_ViewDataTable::factory('table');
            $view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getWeekdayAnalysis' );

            $cols = array('dayname', 'revenue', 'revshare', 'cancel', 'cancshare', 'cancpercent');
            $view->setColumnsToDisplay($cols);
            $view->setColumnTranslation('dayname', Piwik_Translate('OxidPlugin_Weekday'));
            $view->setColumnTranslation('revenue', Piwik_Translate('OxidPlugin_Revenue'));
            $view->setColumnTranslation('revshare', Piwik_Translate('OxidPlugin_Percentage'));
            $view->setColumnTranslation('cancel', Piwik_Translate('OxidPlugin_Storno'));
            $view->setColumnTranslation('cancshare', Piwik_Translate('OxidPlugin_Percentage'));
            $view->setColumnTranslation('cancpercent', Piwik_Translate('OxidPlugin_StornoPercentage'));
            $view->setSortedColumn('dayname', 'asc');

            $view->setLimit( 30 );
            $view->disableExcludeLowPopulation();
            $view->disableFooterIcons();
            $view->disableSearchBox();
            $view->disableRowEvolution();
            return $this->renderView($view, $fetch);
	}

        
        function oxidMenuTopSeller()
	{
		$view = Piwik_ViewDataTable::factory('table');
		$view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getTopSeller' );
		
		$view->setColumnsToDisplay(array('artno', 'arttitle', 'artcount', 'artrev'));
		$view->setColumnTranslation('artno', Piwik_Translate('OxidPlugin_ArtNo'));
		$view->setColumnTranslation('arttitle', Piwik_Translate('OxidPlugin_ArtTitle'));
		$view->setColumnTranslation('artcount', Piwik_Translate('OxidPlugin_Count'));
		$view->setColumnTranslation('artrev', Piwik_Translate('OxidPlugin_Revenue'));
		$view->setSortedColumn('artcount', 'desc');
		
		$view->setLimit( 30 );
		$view->disableExcludeLowPopulation();
		$view->disableFooterIcons();
		$view->disableSearchBox();
                $view->disableRowEvolution();
		return $this->renderView($view);
	}
	
	
	function oxidMenuTopCancels()
	{
		$view = Piwik_ViewDataTable::factory('table');
		$view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getTopCancels' );
		
		$view->setColumnsToDisplay(array('artno', 'arttitle', 'artcount', 'artrev'));
		$view->setColumnTranslation('artno', Piwik_Translate('OxidPlugin_ArtNo'));
		$view->setColumnTranslation('arttitle', Piwik_Translate('OxidPlugin_ArtTitle'));
		$view->setColumnTranslation('artcount', Piwik_Translate('OxidPlugin_Count'));
		$view->setColumnTranslation('artrev', Piwik_Translate('OxidPlugin_Revenue'));
		$view->setSortedColumn('artcount', 'desc');
		
		$view->setLimit( 30 );
		$view->disableExcludeLowPopulation();
		$view->disableFooterIcons();
		$view->disableSearchBox();
                $view->disableRowEvolution();
		return $this->renderView($view);
	}
	
	
	function oxidMenuAgeAnalysis()
	{
		include PIWIK_INCLUDE_PATH . '/plugins/OxidPlugin/conf/'.'config.inc.php';

		$view = Piwik_ViewDataTable::factory('table');
		$view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getAgeAnalysis' );
		
		$cols = array('ageclass', 'mencount', 'womencount', 'menrevenue', 'womenrevenue');
		$payments = getOxPayments($this);
		foreach ($payments as $payment)
			array_push($cols, $payment);
		$view->setColumnsToDisplay($cols);
		$view->setColumnTranslation('ageclass', Piwik_Translate('OxidPlugin_AgeClass'));
		$view->setColumnTranslation('mencount', Piwik_Translate('OxidPlugin_MenCount2'));
		$view->setColumnTranslation('womencount', Piwik_Translate('OxidPlugin_WomenCount2'));
		$view->setColumnTranslation('menrevenue', Piwik_Translate('OxidPlugin_MenRevenue2'));
		$view->setColumnTranslation('womenrevenue', Piwik_Translate('OxidPlugin_WomenRevenue2'));
		$view->setSortedColumn('ageclass', 'asc');
		
		$view->setLimit( 30 );
		$view->disableExcludeLowPopulation();
		$view->disableFooterIcons();
		$view->disableSearchBox();
                $view->disableRowEvolution();
		return $this->renderView($view);
	}
	
	
	function oxidMenuStoreStatus()
	{
		include PIWIK_INCLUDE_PATH . '/plugins/OxidPlugin/conf/'.'config.inc.php';

		$view = Piwik_ViewDataTable::factory('table');
		$view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getStoreStatus' );
		
		$cols = array('oxartnum', 'oxtitle', 'oxvarselect', 'oxdelivery', 'oxnostocktext');
		$view->setColumnsToDisplay($cols);
		$view->setColumnTranslation('oxartnum', Piwik_Translate('OxidPlugin_ArtNo'));
		$view->setColumnTranslation('oxtitle', Piwik_Translate('OxidPlugin_ArtTitle'));
		$view->setColumnTranslation('oxvarselect', Piwik_Translate('OxidPlugin_VarTitle'));
		$view->setColumnTranslation('oxdelivery', Piwik_Translate('OxidPlugin_DeliveryDate'));
		$view->setColumnTranslation('oxnostocktext', Piwik_Translate('OxidPlugin_DeliveryInfo'));
		$view->setSortedColumn('oxartnum', 'asc');
		
		$view->setLimit( 30 );
		$view->disableExcludeLowPopulation();
		$view->disableFooterIcons();
		$view->disableSearchBox();
                $view->disableRowEvolution();
		return $this->renderView($view);
	}
	
	
	function oxidMenuManufacturerRevenue()
	{

            echo '<table width="100%">';
            echo '<tr><td colspan="2">';
                $this->echoTop5DelivererRevenueGraph();
            echo '</td></tr>';
            echo '<tr><td style="vertical-align: top;"><p> </p>';
		$this->echoManuRevenueGraph();
            echo '</td><td style="vertical-align: top;"><p></p><p>';
		$view = Piwik_ViewDataTable::factory('table');
		$view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getManufacturerRevenue' );

                $cols = array('deliverer', 'totalcount', 'netmargin', 'percentnet', 'brutsum', 'percentbrut');
		$view->setColumnsToDisplay($cols);
		$view->setColumnTranslation('deliverer', Piwik_Translate('OxidPlugin_Manufacturer'));
		$view->setColumnTranslation('totalcount', Piwik_Translate('OxidPlugin_Count'));
		$view->setColumnTranslation('netmargin', Piwik_Translate('OxidPlugin_Margin'));
		$view->setColumnTranslation('percentnet', Piwik_Translate('OxidPlugin_Percentage'));
		$view->setColumnTranslation('brutsum', Piwik_Translate('OxidPlugin_Revenue'));
		$view->setColumnTranslation('percentbrut', Piwik_Translate('OxidPlugin_Percentage'));
		$view->setSortedColumn('brutsum', 'desc');
		
		$view->setLimit( 30 );
		$view->disableExcludeLowPopulation();
		//$view->disableFooterIcons();

                $view->disableExcludeLowPopulation();
                // hide goals and metrics icons
                $view->disableShowAllColumns();
                $view->disableShowAllViewIcons();
                $view->alwaysShowLimitDropdown();
                //$view->showLimitDropdown();
                $view->disableSearchBox();
                $view->disableRowEvolution();
                // hide all chart icons
                $view->disableShowAllViewsIcons();
                $view->disableShowExportAsRssFeed();  
                
		$view->disableSearchBox();
                $view->disableRowEvolution();
		$this->renderView($view);
            echo '</td></tr>';/*--*/
            echo '</table>';

            return;
	}
	
	
	function oxidMenuVendorRevenue()
	{

            echo '<table width="100%"><tr><td style="vertical-align: top;">';
		$this->echoVendorRevenueGraph();
            echo '</td><td style="vertical-align: top;"><p></p><p>';
		$view = Piwik_ViewDataTable::factory('table');
		$view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getVendorRevenue' );
		
		$cols = array('deliverer', 'totalcount', 'netmargin', 'percentnet', 'brutsum', 'percentbrut');
		$view->setColumnsToDisplay($cols);
		$view->setColumnTranslation('deliverer', Piwik_Translate('OxidPlugin_Vendor'));
		$view->setColumnTranslation('totalcount', Piwik_Translate('OxidPlugin_Count'));
		$view->setColumnTranslation('netmargin', Piwik_Translate('OxidPlugin_Margin'));
		$view->setColumnTranslation('percentnet', Piwik_Translate('OxidPlugin_Percentage'));
		$view->setColumnTranslation('brutsum', Piwik_Translate('OxidPlugin_Revenue'));
		$view->setColumnTranslation('percentbrut', Piwik_Translate('OxidPlugin_Percentage'));
		$view->setSortedColumn('brutsum', 'desc');
		
		$view->setLimit( 30 );
		$view->disableExcludeLowPopulation();
		$view->disableFooterIcons();
		$view->disableSearchBox();
                $view->disableRowEvolution();
		$this->renderView($view);
            echo '</td></tr></table>';

            return;
	}
	
	
	function echoRevenueGraph()
	{
		$view = Piwik_ViewDataTable::factory('graphEvolution');
		$view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getRevenueEvolution' );
		$view->setColumnTranslation('revenue', Piwik_Translate('OxidPlugin_Revenue'));
		$view->setAxisYUnit(Piwik::getCurrency(Piwik_Common::getRequestVar('idSite')));        // useful if the user requests the bar graph
		return $this->renderView($view);
	}
	
	
	function echoTop5DelivererRevenueGraph()
	{
            include PIWIK_INCLUDE_PATH . '/plugins/OxidPlugin/conf/'.'config.inc.php';
            $view = Piwik_ViewDataTable::factory('graphEvolution');
            $view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getTop5DelivererRevenueGraph' );
            /*$ColumnLabel = explode('|', $this->ColumnLabels);
            $txt = $ColumnLabel[0];*/
            //logfile('debug', 'ColumnLabel0'.$this->ColumnLabel[0]);
            //$txt = $this->ColumnLabel[0];
            //$view->setColumnTranslation('revenue0', $txt);
            
            $labelNames = $this->getTop5DelivererRevenueNames();
            for ($i=0; $i<count($labelNames); $i++)
                $view->setColumnTranslation("revenue{$i}", $labelNames[$i]['oxtitle']);

            /*$view->setColumnTranslation('revenue0', 'Heck-Pack');
            $view->setColumnTranslation('revenue1', 'Ruffwear');
            $view->setColumnTranslation('revenue2', 'Travall');
            $view->setColumnTranslation('revenue3', 'Dörr');
            $view->setColumnTranslation('revenue4', '4Pets');*/
            $view->setAxisYUnit(Piwik::getCurrency(Piwik_Common::getRequestVar('idSite')));        // useful if the user requests the bar graph
            return $this->renderView($view);
	}
        
        
        //
        public function getTop5DelivererRevenueNames()
        {
            include PIWIK_INCLUDE_PATH . '/plugins/OxidPlugin/conf/'.'config.inc.php';

            if ($this->DebugMode) logfile('debug', 'getTop5DelivererRevenueNames(): WELCOME');
            $this->SiteID = Piwik_Common::getRequestVar('idSite');
            $db = openDB($this);

            $date = Piwik_Common::getRequestVar('date');
            $period = Piwik_Common::getRequestVar('period');
            $this->Currency = Piwik::getCurrency(Piwik_Common::getRequestVar('idSite'));
            if ($this->DebugMode) logfile('debug', 'getTop5DelivererRevenueNames(): date='.$date);
            if ($this->DebugMode) logfile('debug', 'getTop5DelivererRevenueNames(): period='.$period);
            
            if ($period == 'range') {
                $dateStart = substr($date, 0, strpos($date, ',')); 
                $dateEnd = substr($date, strpos($date, ',')+1);  
            } else {
                $timePeriod = new Piwik_Period_Range($period, 'last3');
                $dateStart = $timePeriod->getDateStart()->toString('Y-m-d'); 
                $dateEnd = $timePeriod->getDateEnd()->toString('Y-m-d');
            }
            if ($this->DebugMode) logfile('debug', 'getTop5DelivererRevenueNames: AFTER PERIOD  ');
            
            // retrieve the top5 deliverer
            //$sql = "SELECT m.oxid, m.oxtitle, SUM(d.oxamount) AS artcount, SUM(d.oxbrutprice) AS sumprice "
            $sql = "SELECT  m.oxtitle "
                 . "FROM oxorderarticles d, oxarticles a, oxmanufacturers m, oxorder o "
                 . "WHERE d.oxartid = a.oxid "
                        . "AND IF(a.oxmanufacturerid!='', "
                            . "a.oxmanufacturerid, "
                            . "(SELECT a2.oxmanufacturerid FROM oxarticles a2 WHERE a.oxparentid=a2.oxid)) "
                            . "= m.oxid "
                        . "AND d.oxstorno = 0 "
                        . "AND d.oxorderid = o.oxid "
                        . "AND DATE(o.oxorderdate) >= '{$dateStart}' " 
                        . "AND DATE(o.oxorderdate) <= '{$dateEnd}' "
                 . "GROUP BY m.oxtitle "
                 . "ORDER BY SUM(d.oxbrutprice) DESC "
                 . "LIMIT 0, 5 ";

            if ($this->DebugMode) logfile('debug', 'getTop5DelivererRevenueNames: '.$sql);
            $stmt = $db->prepare($sql);
            $stmt->execute();
            $dbData = $stmt->fetchAll(PDO::FETCH_NAMED);
            if ($this->DebugMode) logfile('debug', $dbData);
            
            return $dbData;
        }
	
	
	function echoManuRevenueGraph()
	{
		$view = Piwik_ViewDataTable::factory('graphVerticalBar');
		$view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getManufacturerRevenueGraph' );
		$view->setColumnTranslation('value', Piwik_Translate('OxidPlugin_Revenue'));
		$view->setAxisYUnit(Piwik::getCurrency(Piwik_Common::getRequestVar('idSite')));        // useful if the user requests the bar graph
		$view->setGraphLimit( 100 );
		$view->disallowPercentageInGraphTooltip();
		return $this->renderView($view);
	}
	
	
	function echoVendorRevenueGraph()
	{
		$view = Piwik_ViewDataTable::factory('graphVerticalBar');
		$view->init( $this->pluginName,  __FUNCTION__, 'OxidPlugin.getVendorRevenueGraph' );
		$view->setColumnTranslation('value', Piwik_Translate('OxidPlugin_Revenue'));
		$view->setAxisYUnit(Piwik::getCurrency(Piwik_Common::getRequestVar('idSite')));        // useful if the user requests the bar graph
		$view->setGraphLimit( 100 );
		$view->disallowPercentageInGraphTooltip();
		return $this->renderView($view);
	}
	
	
}
